package tgc.edu.examxy.web.controller;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import tgc.edu.examxy.entity.Student;
import tgc.edu.examxy.security.User2;
import tgc.edu.examxy.service.StudentService;
import tgc.edu.examxy.service.SysFileService;
import tgc.edu.examxy.web.form.RegisterForm;

@Controller
@RequestMapping(value="/student")
public class StudentController {
	@Autowired
	private StudentService studentservice;
	@Autowired
	private SysFileService fileservice;
	/***
	 * 跳转个人信息页面
	 * @return
	 */
	@RequestMapping(value = "/message")
	private String meassage(ModelMap map) {
		SecurityContext ctx = SecurityContextHolder.getContext();
	    Authentication auth = ctx.getAuthentication();
	    User2 user = (User2) auth.getPrincipal();
	    studentservice.findByUsername(user.getUsername());
	    map.put("model", studentservice.findByUsername(user.getUsername()));
		return "student/message";
	}
	@RequestMapping(value = "/save")
	private String save(RegisterForm form,String id) {
		Student findById = studentservice.findById(UUID.fromString(id));
		findById.setFileuuid(form.getFileuuid());
		findById.setEmail(form.getEmail());
		findById.setOfficetel(form.getOfficetel());
		findById.setJob(form.getJob());
		findById.setJobLevel(form.getJobLevel());
		findById.setPostalCode(form.getPostalCode());
		findById.setSpeciality(form.getSpeciality());
		findById.setCarnumber(form.getCarnumber());
		findById.setAddress(form.getAddress());
		findById.setPhone(form.getPhone());
		findById.setWorkUnit(form.getWorkUnit());
		studentservice.save(findById);
		fileservice.DeleteAll(form.getFileuuid());
		return "redirect:../main1";
	}
	/** 跳转课件资源 **/
	
	
	
	/***
	 * 跳转课程页面
	 * @return
	 */
	@RequestMapping(value = "/home")
	private String home() {
		return "student/home";
	}
	/***
	 * 跳转课程页面
	 * @return
	 */
	@RequestMapping(value = "/schedule")
	private String schedule() {
		return "student/schedule";
	}
	
	@RequestMapping(value = "/alumnibook")
	private String alumnibook() {
		return "student/alumnibook";
	}
	
	@RequestMapping(value = "/bwh")
	private String bwh() {
		return "student/bwh";
	}
	
	@RequestMapping(value = "/kjzy")
	private String kjzy() {
		return "student/kjzy";
	}
	
	@RequestMapping(value = "/kqqd")
	private String kqqd() {
		return "student/kqqd";
	}
	
	@RequestMapping(value = "/wdcj")
	private String wdcj() {
		return "student/wdcj";
	}
	
	@RequestMapping(value = "/zxkt")
	private String zxkt() {
		return "student/zxkt";
	}
	
	@RequestMapping(value = "/fzmd")
	private String fzmd() {
		return "student/fzmd";
	}
	@RequestMapping(value = "/qjsq")
	private String qjsq() {
		return "student/qjsq";
	}
	@RequestMapping(value = "/kc")
	private String kc() {
		return "student/kc";
	}
	@RequestMapping(value = "/js")
	private String js() {
		return "student/js";
	}
}
